package org.nextive.android.weightapp.utils;

import java.util.ArrayList;

import org.nextive.android.weightapp.R;
import org.nextive.android.weightapp.entities.AccountData;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class AccountAdapter extends ArrayAdapter<AccountData> 
{
	private LayoutInflater layoutInflater;
	
	public AccountAdapter(Context context, LayoutInflater layoutInflater, ArrayList<AccountData> account) 
	{
		super(context, android.R.layout.simple_spinner_item, account);
		setDropDownViewResource(R.layout.account_entry);
		this.layoutInflater = layoutInflater;
	}
	
	public View getDropDownView(int position, View convertView, ViewGroup parent) 
	{
        if (convertView == null) 
        {
            convertView = layoutInflater.inflate(R.layout.account_entry, parent, false);
        }
        TextView firstAccountLine = (TextView) convertView.findViewById(R.id.textViewAccountName);
        TextView secondAccountLine = (TextView) convertView.findViewById(R.id.textViewAccountNameType);
        
        AccountData account = getItem(position);
        firstAccountLine.setText(account.getName());
        secondAccountLine.setText(account.getLabelType());
        return convertView;
    }
}
